package chapter26;

public class Chapter26Main {

    public static void main(String[] args) throws CloneNotSupportedException {
        FordFulkerson.EdgeNode s = new FordFulkerson.EdgeNode('0', 0);
        FordFulkerson.EdgeNode v1 = new FordFulkerson.EdgeNode('1', 1);
        FordFulkerson.EdgeNode v2 = new FordFulkerson.EdgeNode('2', 2);
        FordFulkerson.EdgeNode v3 = new FordFulkerson.EdgeNode('3', 3);
        FordFulkerson.EdgeNode v4 = new FordFulkerson.EdgeNode('4', 4);
        FordFulkerson.EdgeNode t = new FordFulkerson.EdgeNode('5', 5);

        FordFulkerson.insert(s, new FordFulkerson.EdgeNode('1', 1), 16);
        FordFulkerson.insert(s, new FordFulkerson.EdgeNode('2', 2), 13);
        FordFulkerson.insert(v1, new FordFulkerson.EdgeNode('3', 3), 12);
        FordFulkerson.insert(v2, new FordFulkerson.EdgeNode('1', 1), 4);
        FordFulkerson.insert(v2, new FordFulkerson.EdgeNode('4', 4), 14);
        FordFulkerson.insert(v3, new FordFulkerson.EdgeNode('2', 2), 9);
        FordFulkerson.insert(v3, new FordFulkerson.EdgeNode('5', 5), 20);
        FordFulkerson.insert(v4, new FordFulkerson.EdgeNode('3', 3), 7);
        FordFulkerson.insert(v4, new FordFulkerson.EdgeNode('5', 5), 4);

        FordFulkerson.Graph G = new FordFulkerson.Graph();
        G.adjList.add(new FordFulkerson.VertexNode(s));
        G.adjList.add(new FordFulkerson.VertexNode(v1));
        G.adjList.add(new FordFulkerson.VertexNode(v2));
        G.adjList.add(new FordFulkerson.VertexNode(v3));
        G.adjList.add(new FordFulkerson.VertexNode(v4));
        G.adjList.add(new FordFulkerson.VertexNode(t));

        G.numVertexes = 6;
        G.numEdges = 9;

        FordFulkerson.Graph Gf = FordFulkerson.fordFulkerson(G, s, t);
        FordFulkerson.EdgeNode tf = Gf.adjList.get(t.adj).firstEdge.next;
        int max = 0;
        while (tf != null) {
            max += tf.f;
            tf = tf.next;
        }
        System.out.println(max);


//        PushRelabel.EdgeNode ss = new PushRelabel.EdgeNode('s',0);
//        PushRelabel.EdgeNode x = new PushRelabel.EdgeNode('x',1);
//        PushRelabel.EdgeNode y = new PushRelabel.EdgeNode('y',2);
//        PushRelabel.EdgeNode z = new PushRelabel.EdgeNode('z',3);
//        PushRelabel.EdgeNode tt = new PushRelabel.EdgeNode('t',4);
//
//        PushRelabel.insert(ss, new PushRelabel.EdgeNode('x',1),12);
//        PushRelabel.insert(ss, new PushRelabel.EdgeNode('y',2),14);
//        PushRelabel.insert(x, new PushRelabel.EdgeNode('y',2),5);
//        PushRelabel.insert(x, new PushRelabel.EdgeNode('t',4),16);
//        PushRelabel.insert(y, new PushRelabel.EdgeNode('z',3),8);
//        PushRelabel.insert(z, new PushRelabel.EdgeNode('x',1),7);
//        PushRelabel.insert(z, new PushRelabel.EdgeNode('t',4),10);
//
//        PushRelabel.Graph GG = new PushRelabel.Graph();
//        GG.adjList.add(new PushRelabel.VertexNode(ss));
//        GG.adjList.add(new PushRelabel.VertexNode(x));
//        GG.adjList.add(new PushRelabel.VertexNode(y));
//        GG.adjList.add(new PushRelabel.VertexNode(z));
//        GG.adjList.add(new PushRelabel.VertexNode(tt));
//
//        GG.numVertexes = 5;
//        GG.numEdges = 7;
//
//        PushRelabel.relabelToFont(GG,ss);
//        System.out.println(tt);

        PushRelabel.EdgeNode ss = new PushRelabel.EdgeNode('s', 0);
        PushRelabel.EdgeNode x = new PushRelabel.EdgeNode('x', 1);
        PushRelabel.EdgeNode y = new PushRelabel.EdgeNode('y', 2);
        PushRelabel.EdgeNode z = new PushRelabel.EdgeNode('z', 3);

        PushRelabel.insert(ss, new PushRelabel.EdgeNode('y', 2), 14);
        PushRelabel.insert(x, new PushRelabel.EdgeNode('y', 2), 5);
        PushRelabel.insert(y, new PushRelabel.EdgeNode('z', 3), 8);

        ss.N.add(new PushRelabel.EdgeNode('y', 2));
        x.N.add(new PushRelabel.EdgeNode('y', 2));
        y.N.add(new PushRelabel.EdgeNode('s', 0));
        y.N.add(new PushRelabel.EdgeNode('x', 1));
        y.N.add(new PushRelabel.EdgeNode('z', 3));
        z.N.add(new PushRelabel.EdgeNode('y', 2));

        PushRelabel.Graph GG = new PushRelabel.Graph();
        GG.adjList.add(new PushRelabel.VertexNode(ss));
        GG.adjList.add(new PushRelabel.VertexNode(x));
        GG.adjList.add(new PushRelabel.VertexNode(y));
        GG.adjList.add(new PushRelabel.VertexNode(z));

        GG.numVertexes = 4;
        GG.numEdges = 3;

        PushRelabel.relabelToFont(GG, ss);
        System.out.println();
    }
}
